package com.sg.zwfw.service.impl;

import com.sg.zwfw.dao.UserMapper;
import com.sg.zwfw.entity.User;
import com.sg.zwfw.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userDao;

    @Override
    public User getUserById(int userId) {
        return userDao.selectByPrimaryKey(userId);
    }

    @Override
    public boolean addUser(User user) {
        boolean result = false;
        try {
            userDao.insert(user);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    @Override
    public List<User> list() {
        return userDao.list();
    }

    @Override
    public boolean updateByPrimaryKey(User user) {
        boolean result = false;
        try {
            userDao.updateByPrimaryKey(user);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public boolean deleteByPrimaryKey(Integer id) {
        boolean result = false;
        try {
            userDao.deleteByPrimaryKey(id);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}